package com.springboot.springbootlogindemo.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.springbootlogindemo.domain.Comments;

import com.springboot.springbootlogindemo.mapper.CommentsMapper;

import com.springboot.springbootlogindemo.service.CommentsService;
import com.springboot.springbootlogindemo.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements CommentsService {

    @Resource
    private CommentsMapper commentsMapper;

    /**
     * 增加评论
     * @param comments
     * @return
     */
    @Override
    public Result addComment(Comments comments) {
        commentsMapper.insert(comments);
        return Result.success("评论成功");
    }

    /**
     * 删除评论
     * @param commentId
     * @return
     */
    @Override
    public Result deleteComment(Long commentId) {
        commentsMapper.deleteById(commentId);
        return Result.success("评论删除成功");
    }

    /**
     * 查询子评论
     * @param commentId
     * @return
     */
    @Override
    public Result showCommentComments(Long commentId) {
        List<Comments> list = query().eq("type", 3).eq("parent_id", commentId).list();
        return Result.success(list,"查询成功");
    }

    /**
     * 查询歌曲评论
     * @param songId
     * @return
     */
    @Override
    public Result showSongComments(Long songId) {
        List<Comments> list = query().eq("type", 2).eq("parent_id", songId).list();
        return Result.success(list,"查询成功");
    }

    /**
     * 查询歌单评论
     * @param songListId
     * @return
     */
    @Override
    public Result showSongListComments(Long songListId) {
        List<Comments> list = query().eq("type", 1).eq("parent_id", songListId).list();
        return Result.success(list,"查询成功");
    }
}
